module game{
    export class EventConst{
        public static Remove_Candy:number = 10001;
        public static Item_Num_Updata:number = 10002;
    }

    export enum EdgeType{
        Left = 0,
        Right,
        Down,
        Up
    }
    export class GameData{
        //历史最高分(从微信获取)
        public historyScore:number = 0;
        //当前地图(下一版本)
        public mapDic:{[index:number]:number} = {};
        //前置3张地图
        public preMapDic = [];
        //当前进度
        public curmax = 6;
        //全场最小数字
        public min = 6;


        //当前提示目标
        public targetNumber = 15;

        //当前礼包锤子道具数量
        private hammarNum = 0;
        //当前礼包重置道具数量
        private resetNum = 0;
        //当前分享锤子道具数量
        private sHammarNum = 0;
        //当前分享重置道具数量
        private sResetNum = 0;

        
        //单局使用数量
        public hammarCount = 3;
        public resetCount = 3;

        //道具上限
        public maxItem = 20;

        //复活次数
        public reviveCount = 2;
        
        // public isReseting:boolean = false;
        public isHammaring:boolean = false;
        public config:{[key:number]:number[]};

        public tips:string[];

        constructor(){
            this.config = {};
            this.config[5] = [0.35 , 0.35 , 0.20 , 0.05 , 0.05];
            this.config[6] = [0.35 , 0.25 , 0.20 , 0.10 , 0.05, 0.05];
            this.config[7] = [0.30 , 0.30 , 0.20 , 0.05 ,0.05 , 0.05 , 0.05];

            this.tips = [
                "点击相邻的相同色块进行合成哦",
                "尽量让相同的数字在一起",
                "合理的点击合成位置很重要哦",
                "关键时刻小锤子很有用哦",
                "点错了可以使用撤销进行弥补哦",
                "合成到10就是天才了"
            ]
        }

        public reset(){
            this.curmax = 6;
            this.hammarNum = 1;
            this.resetNum = 1;
            this.reviveCount = 2;
            this.maxItem = 20;
            this.mapDic = {};
            this.preMapDic = [];
            this.resetItem();

            // this.test();
        }

        public resetItem(){
            
            this.resetCount = 10;
            this.hammarCount = 10;
        }

        private test(){
            // this.curmax = 13;
            this.hammarNum = 20;
            // this.hammarCount = 0;

            this.resetNum = 20;
            // this.resetCount = 1000;

        }


        //礼包增加道具
        public addResetItem(){
            if(this.getAllReset() >= this.maxItem){
                return;
            }
            this.resetNum+=1;
            App.ControllerManager.applyFunc(ControllerConst.Core,EventConst.Item_Num_Updata,this);
        }
        public addHammarItem(){
            if(this.getAllHammar() >= this.maxItem){
                return;
            }
            this.resetNum+=1;
            App.ControllerManager.applyFunc(ControllerConst.Core,EventConst.Item_Num_Updata,this);
        }

        //分享增加道具
        public addSResetItem(){
            if(this.getAllReset() >= this.maxItem){
                return;
            }
            this.sResetNum+=1;
            App.ControllerManager.applyFunc(ControllerConst.Core,EventConst.Item_Num_Updata,this);
        }

        public addSHammarItem(){
            if(this.getAllHammar() >= this.maxItem){
                return;
            }
            this.sHammarNum+=1;
            App.ControllerManager.applyFunc(ControllerConst.Core,EventConst.Item_Num_Updata,this);
        }


        //得到全部数量
        public getAllHammar(){
            return this.hammarNum +this.sHammarNum;
        }
        public getAllReset(){
             return this.resetNum +this.sResetNum;
        }

        //消耗道具
        public removeResetItem(){
            if(this.sResetNum > 0){
                this.sResetNum -= 1;
            }else{
                this.resetNum -= 1;
            }
        }

        public removeHammarItem(){
            if(this.sHammarNum > 0){
                this.sHammarNum -= 1;
            }else{
                this.sHammarNum -= 1;
            }
        }

        public saveWXData(){
            //存储当前地图信息

            let self = this;

            platform.setStorageSync("curmax",self.curmax); 

            platform.setStorageSync("map",self.mapDic);
            //道具
            platform.setStorageSync("hammarNum",self.hammarNum);
            platform.setStorageSync("hammarCount",self.hammarCount);

            platform.setStorageSync("resetNum",self.resetNum);
            platform.setStorageSync("resetCount",self.resetCount);

            platform.setStorageSync("reviveCount",self.reviveCount);

            platform.setStorageSync("preMap",self.preMapDic);

            platform.setStorageSync("sHammarNum",self.sHammarNum); 
            platform.setStorageSync("sResetNum",self.sResetNum); 
        }

        public getWXData(){
            let self = this;
            self.mapDic = platform.getStorageSync("map")||{};
            //道具
            self.hammarNum = platform.getStorageSync("hammarNum");
            self.hammarCount = platform.getStorageSync("hammarCount");
            self.resetNum = platform.getStorageSync("resetNum");
            self.resetCount = platform.getStorageSync("resetCount");

            self.reviveCount = platform.getStorageSync("reviveCount");

            self.preMapDic = platform.getStorageSync("preMap")||[]; 

            self.curmax = platform.getStorageSync("curmax");
            self.sHammarNum = platform.getStorageSync("sHammarNum")||0; 
            self.sResetNum = platform.getStorageSync("sResetNum")||0; 

            //没有数据就初始化
            let type = self.mapDic["0_0"];
            if(!type){
                this.reset();
            }
        }

    }

    export let  gameData = new GameData();
}